package com.credithc.eagleeye.spring.starter;
import com.credithc.eagleeye.plugins.mvc.EagleEyeMvcAspect;
import com.credithc.eagleeye.plugins.mvc.EagleEyeMvcFilter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.core.Ordered;
/**
 * 描 述: <br/>
 * 作 者: zhangjin<br/>
 * 创 建：2019年10月22日<br/>
 * 版 本：v1.0.0<br>
 * <p>
 * 历 史: (版本) 作者 时间 注释 <br/>
 */
@Configuration
@EnableAspectJAutoProxy
@ConditionalOnWebApplication
@ConditionalOnClass(name={"org.springframework.web.bind.annotation.RequestMapping","javax.servlet.Filter","org.springframework.boot.web.servlet.FilterRegistrationBean"})
public class EagleEyeWebmvcAutoConfiguration {

    @Bean
    @ConditionalOnClass(name = "org.aspectj.lang.ProceedingJoinPoint")
    @ConditionalOnMissingBean({EagleEyeMvcAspect.class})
    public EagleEyeMvcAspect eagleEyeMvcAspect() {
        return new EagleEyeMvcAspect();
    }

    @Bean
    public FilterRegistrationBean eagleEyeMvcFilterRegistrationBean() {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        registrationBean.setFilter(new EagleEyeMvcFilter());
        registrationBean.setName("eagleEyeMvcFilter");
        registrationBean.addUrlPatterns("/*");
        //最低级
        registrationBean.setOrder(Ordered.LOWEST_PRECEDENCE);
        return registrationBean;
    }

}
